#!/bin/sh
#

# This script is called from /usr/src/e2920-3.0.0 
# in order to perform an installation when using a tar-archive
# (instead of an .rpm package)

# Install shared libraries (.so files)
mkdir /usr/lib/agilent

# Couldn't use cp as it sometimes just copies the links instead of
# the files referenced by them (depends on Linux distribution)
#cp lib/* /usr/lib/agilent
# replaced by:
cd ./lib
tar cv * | tar xvC /usr/lib/agilent
cd ..

# Install documentation
mkdir /usr/share/doc/e2920-3.0.0
cp README /usr/share/doc/e2920-3.0.0

# Compile and install PCI driver
cd drivers
make
make install

# Add /usr/lib/agilent to /etc/ld.so 
# This is needed by ldconfig to create symb. links
if ! grep /usr/lib/agilent /etc/ld.so.conf &> /dev/null
then
  echo /usr/lib/agilent >> /etc/ld.so.conf
fi

# Create character special devices for accessing the driver.
# 123 is our major device number (for local experimantal use)
# (see /usr/src/linux/Documentation/devices.txt).
# Its is #defined in b_pci.h
# REMARK:
#    If you are using the devfs (optional available since Kernel 2.4),
#    you will have to load the driver manually by executing:
#    > modprobe best_pci
#    as root from the command line.   
#    You dont have to execute mknod in this case, because the devfs
#    automatically creates the existing PCI devices.
if [ ! -d /dev/best ]
then
  mkdir /dev/best
  i=0
  while [ $i -lt 256 ]
  do
    mknod /dev/best/pci$i c 123 $i
    i=$[$i+1]
  done
fi

# Add some entries to /etc/modules.conf
# This is needed for automatic loading of best_pci.o
# when /dev/best/pci? is accessed.
if ! grep best_pci /etc/modules.conf &> /dev/null
then
  echo alias char-major-123 best_pci >> /etc/modules.conf
fi

# Create symbolic links in /usr/lib/agilent/ to most recent libraries
# This guarantees linkage to the newest installed library
# (Linker option -lxcapilx resp. -lcapilx)
ldconfig

echo Agilent E2920-Series Linux Suite successfully installed.
echo
